<template>
    <div class="listDiv">
        <div class="searchDiv">
            <DatePicker v-model:value="obj.req.intime" width="150" class="mr10"/>
            <el-select v-model="obj.req.state" placeholder="全部状态" class="search_select" clearable>
                <el-option v-for="(item,index) in globalData.stateTypeAry" :key="index" :label="item.text" :value="item.value" />
            </el-select>
            <el-select v-model="obj.req.timestate" placeholder="时间状态" class="search_select" clearable>
                <el-option v-for="(item,index) in globalData.timestateAry.slice(0,3)" :key="index" :label="item.text" :value="item.value" />
            </el-select>
            <el-input clearable placeholder="匹配招聘会/地点" v-model="obj.req.key" class="search_key" />
            <span class="btn search" @click="init">搜索</span>
            <span class="btn refresh" @click="obj.req.currentpage=1;init()"></span>
            <!-- <span class="btn download" @click="export_"></span> -->
            <div class="searchRight">
                <span class="btn add" @click="add">添加招聘会</span>
            </div>
        </div>
        <div class="table_box"><div class="table_" id="tb">
            <ul class="head">
                <li class="mw300">招聘会名称</li>
                <li class="mw180">地址</li>
                <li class="mw240 wcen">有效时段</li>
                <li class="wcen">状态</li>
                <li class="">联系人</li>
                <li class="wcen">联系方式</li>
                <li class="mw100 wcen">正常/停用</li>
                <li class="wcen">企业预约</li>
                <li class="wcen">个人预约</li>
                <li class="mw200 wcen">操作</li>
            </ul>
            <div class="body">
                <ul v-for="x in obj.ary" :key="x">
                    <li class="mw300">
                        <el-tooltip class="box-item" effect="dark" :content="x.title" placement="top-start" :disabled="x.title.length<17">
                            <div class="lineOne pointer">{{x.title}}</div>
                        </el-tooltip>
                    </li>
                    <li class="mw180">
                        <el-tooltip class="box-item" effect="dark" :content="x.address" placement="top-start" :disabled="x.address.length<9">
                            <div class="lineOne pointer">{{x.address}}</div>
                        </el-tooltip>
                    </li>
                    <li class="mw240 wcen">{{x.starttime}} 至 {{x.endtime}}</li>
                    <li class="wcen">
                        <div :class="[fix(x).label]">{{fix(x).text||''}}</div>
                    </li>
                    <li class="">{{x.man}}</li>
                    <li class="wcen">{{x.mobile}}</li>
                    <li class="mw100 wcen">
                        <el-switch v-model="x.state" size="small" :validate-event="false" @change="setstate(x)"
                            active-text="" inactive-text=""
                            active-value="1" inactive-value="0">
                        </el-switch>
                    </li>
                    <li class="base-color pointer wcen"><u @click="companyCou(x)">{{x.companyCou}}</u></li>
                    <li class="base-color pointer wcen"><u @click="persionCou(x)">{{x.persionCou}}</u></li>
                    <li class="mw200 wcen">
                        <el-button class="edit_btn mr10" type="success" @click="edit(x)">修改</el-button>
                        <DelConfirm class="" @yesClick="del(x)" />
                    </li>
                </ul>
            </div>
        </div>
        </div><Pager :value="obj.req" :init="init" />

        <el-dialog v-model="obj.drawer.design" :title="obj.drawer.designTitle" width="1000px" :close-on-click-modal="false" :destroy-on-close="true">
            <Edit :jobfair_id="obj.drawer.jobfair_id" @close="obj.drawer.design = false" @init="init" />
        </el-dialog>
        <el-dialog v-model="obj.drawer.company" :title="obj.drawer.companyTitle" width="1000px" :close-on-click-modal="false" :destroy-on-close="true">
            <Company :jobfair_id="obj.drawer.jobfair_id" @close="obj.drawer.company = false" />
        </el-dialog>
        <el-dialog v-model="obj.drawer.persion" :title="obj.drawer.persionTitle" width="1000px" :close-on-click-modal="false" :destroy-on-close="true">
            <Persion :jobfair_id="obj.drawer.jobfair_id" @close="obj.drawer.persion = false" />
        </el-dialog>
    </div>
</template>

<script setup>
    import { reactive, getCurrentInstance, ref, toRefs, provide, computed } from 'vue'
    import Pager from '@/components/pager.vue'
    import DelConfirm from '@/components/del_confirm.vue'
    import DatePicker from '@/components/date_picker.vue'
    import Edit from "./edit.vue"
    import Company from "./company.vue"
    import Persion from "./persion.vue"
    let { proxy } = getCurrentInstance()

    let obj = reactive({
        drawer: {
            jobfair_id:"",
            design: false,
            designTitle: "",
            company: false,
            companyTitle: "",
            persion: false,
            persionTitle: "",
        },
        ary: [],
        req: {
            currentpage: 1,
            pagesize: 10,
            count: 0,
            key: "",
            state:"",
            timestate: "",
            intime: ''
        }
    });
    let init = () => {
        proxy.$ajax({
            url: '/jobfair/list',
            data: obj.req,
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                obj.ary = d.msg.list
                obj.req.count = d.msg.count
            }
        }).catch(() => { })
    }

    let add = () => {
        obj.drawer.design = true
        obj.drawer.designTitle = "添加招聘会"
        obj.drawer.jobfair_id = "0";
    }
    let edit = x => {
        obj.drawer.design = true
        obj.drawer.designTitle = "修改招聘会"
        obj.drawer.jobfair_id = x.id;
    }

    let companyCou = x => {
        obj.drawer.company = true
        obj.drawer.companyTitle = `${x.title} 企业预约列表`
        obj.drawer.jobfair_id = x.id;
    }
    let persionCou = x => {
        obj.drawer.persion = true
        obj.drawer.persionTitle = `${x.title} 个人预约列表`
        obj.drawer.jobfair_id = x.id;
    }

    let fix = computed(() => {
        return (x) => {
            // if(x.complete == 1) return {text:"完成",color:'success-color',label:'label-btn-success'}
            let start = new Date(x.starttime), end = new Date(x.endtime), now = new Date()
            if (start > now) return {text:"尚未开始",color:'gray-color',label:'label-btn-warning'}
            if (end < now) return {text:"已结束",color:'gray-color',label:'label-btn-info'}
            return {text:"进行中",color:'base-color',label:'label-btn-success'}
        }
    })

    let setstate = x => {
        proxy.$ajax({
            url: '/jobfair/setstate',
            data: { id: x.id},
            bfLoading: true
        }).then(d => {
            if(d.success){
                proxy.elMessageMixin("状态变更成功", 'success')
                init()
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }
    let del = x => {
        proxy.$ajax({
            url: '/jobfair/delete',
            data: { id: x.id },
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                proxy.elMessageMixin("删除成功", "success")
                init()
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }
</script>

<style scoped>
    ::-webkit-scrollbar { width:10px; background-color: #FFFFFF; }
    .search_select { width:100px!important; }
    .search_key { width:160px!important; }
    #tb ul li.li0 { width: 160px; }
    #tb ul li.li1 { width: 190px; }
    #tb ul li.li2 { width: 60px; }
    #tb ul li.li3 { width: 85px; }
    #tb ul li.li4 { width: 75px; }
    #tb ul li.li5 { width: 75px; }
    #tb ul li.li4 u, #tb ul li.li5 u { cursor: pointer; }
</style>